package org.ainlolcat.ainscience2.model.filter;

import java.util.ArrayList;
import java.util.Collection;

/**
 * Created by IntelliJ IDEA.
 * User: ain
 * Date: 17.06.12
 * Time: 0:05
 * To change this template use File | Settings | File Templates.
 */
public class FilterApplier {
    public <T> Collection<T> apply(Collection<T> data, Filter... filters){
        if (filters == null) return data;
        Collection<T> result = new ArrayList<T>();
        for (T t:data){
            result.add(t);
            for (Filter f: filters){
                if (!f.isValid(t)) { result.remove(t); continue;}
            }
        }
        return result;
    }
}
